package com.itheima.routingkey;

import com.itheima.utils.ConnectionUtil;
import com.rabbitmq.client.*;

import java.io.IOException;


/**
 * @Auther LCSlove
 * @Date 2021-09-06 14:35
 */
public class Consumer2 {
    public static void main(String[] args) throws Exception {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        channel.queueDeclare("direct_queue2", true, false, false, null);
        DefaultConsumer defaultConsumer = new DefaultConsumer(channel) {
            @Override
            public void handleDelivery(String s, Envelope envelope, AMQP.BasicProperties basicProperties, byte[] bytes) throws IOException {
                System.out.println("这是第二个消费者");
                System.out.println("consumerTag:" + s);
                System.out.println("交换机:" + envelope.getExchange() + ";routingKey:" + envelope.getRoutingKey() + ";deliveryTag:" + envelope.getDeliveryTag());
                System.out.println("消息本身:" + new String(bytes, "utf-8"));
            }
        };
        channel.basicConsume("direct_queue2", true, defaultConsumer);
    }
}
